<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>Test Index2</title>
        <%= stylesheet_link_tag "../javascripts/ext/resources/css/ext-all.css" %>
        <%= javascript_include_tag "ext/adapter/prototype/prototype.js" %>
        <%= javascript_include_tag "ext/adapter/prototype/scriptaculous.js" %>
        <%= javascript_include_tag "ext/adapter/prototype/effects.js" %>
        <%= javascript_include_tag "ext/adapter/prototype/ext-prototype-adapter.js" %>
        <%= javascript_include_tag "ext/ext-all-debug.js" %>
        <%= javascript_include_tag "ext/build/locale/ext-lang-zh_CN.js" %>
    </head>
    <body>
        <div id="ordersgrid" style="height:370px;">
        </div>
        <script>
            var sm = new Ext.grid.CheckboxSelectionModel();
            
            var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), sm, {
                header: '编号',
                dataIndex: 'id'
            }, {
                header: '名称',
                dataIndex: 'name'
            }, {
                header: '描述',
                dataIndex: 'descn'
            }]);
            var data = [['1', 'name1', 'descn1'], ['2', 'name2', 'descn2'], ['3', 'name3', 'descn3'], ['4', 'name4', 'descn4'], ['5', 'name5', 'descn5']];
            var ds = new Ext.data.Store({
                proxy: new Ext.data.MemoryProxy(data),
                reader: new Ext.data.ArrayReader({}, [{
                    name: 'id'
                }, {
                    name: 'name'
                }, {
                    name: 'descn'
                }])
            });
            
            
            var ordergridpanel = new Ext.grid.GridPanel({
                el: 'ordersgrid',
                ds: ds,
                cm: cm,
                sm: sm,
                loadMask: true,
                bbar: new Ext.PagingToolbar({
                    pageSize: 2,
                    store: ds,
                    displayInfo: true,
                    displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
                    emptyMsg: "没有记录"
                })
            
            });
            ds.load();
            ordergridpanel.render();
            ds.load({
                params: {
                    start: 0,
                    limit: 10
                }
            });
			
            function getSelectedRowsID(){
                //                var selectionModel = ordergridpanel.getSelectionModel();
                //                var record = selectionModel.getSelected();
                //                var id = record.data['id'];//get each bind data'id
                //                alert(record.length);
                //alert(ds.data.items.length);
				var records = ordergridpanel.getSelectionModel().getSelections();
				var recordx = ds.data.items[0];
				//var hdChecker = ordergridpanel.getEl().child('.x-grid3-hd-checker');
				//hdChecker.addClass('x-grid3-hd-checker-on');
				//sm.selectAll();
//				sm.selectRow(1);
//				sm.selectRow(2);
                sm.selectRows([1,2]);
				for (i=0;i<records.length;i++){
					//alert(ds.getTotalCount());
					alert(records[i].data['id']);
				}
            }
        </script>
        <input type=button value="得到选择的ID" onclick="getSelectedRowsID()"/>
    </body>
</html>